//
//  RW_WebViewController.m
//  SleepApp
//
//  Created by chuangqi on 2021/4/8.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_WebViewController.h"
#import <WebKit/WebKit.h>

@interface RW_WebViewController ()<WKNavigationDelegate,WKUIDelegate>
@property(nonatomic,strong) NSString *url;
@property (nonatomic,strong) WKWebView *webView;

@end

@implementation RW_WebViewController
/** 用户协议 */
+(void)pushProtocolFromVc:(UIViewController *)fromVc{
    RW_WebViewController *vc = [[RW_WebViewController alloc]init];
    vc.title = @"用户协议";
    vc.url = @"https://docs.qq.com/doc/DZnR4YXFRRXVIS0JO";
    [fromVc.navigationController pushViewController:vc animated:YES];
}
/** 隐私政策 */
+(void)pushPrivacFromVc:(UIViewController *)fromVc{
    RW_WebViewController *vc = [[RW_WebViewController alloc]init];
    vc.title = @"隐私协议";
    vc.url = @"https://docs.qq.com/doc/DZlBiZHpndlRzZmpP";
    [fromVc.navigationController pushViewController:vc animated:YES];
}
/** 内容版权 */
+(void)pushCopyrightFromVc:(UIViewController *)fromVc{
    RW_WebViewController *vc = [[RW_WebViewController alloc]init];
    vc.title = @"内容版权";
    vc.url = @"https://docs.qq.com/doc/DZnVjaHFLeW13dVFn";
    [fromVc.navigationController pushViewController:vc animated:YES];
}

- (void)initView{
    self.view.backgroundColor = HexColor(@"f6f6f6");
    [self.contentView addSubview:self.webView];
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self.contentView);
        make.top.mas_equalTo(self.contentView);
    }];
}
- (void)initData{
    [SVProgressHUD show_wl];
    self.webView.userInteractionEnabled = NO;
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
}

-(void)releseViewController{
    [SVProgressHUD dismiss_wl];
}
#pragma mark - 代理
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    [SVProgressHUD dismiss_wl];
    self.webView.userInteractionEnabled = YES;
    if (self.url){
        [webView evaluateJavaScript:@"document.getElementsByClassName(\"header-container--2O03w header-container-show--2mnKa\")[0].style.display=\"none\";" completionHandler:nil];
        [webView evaluateJavaScript:@"document.getElementsByClassName(\"bottom-exposure-container--1yes3\")[0].style.display=\"none\";" completionHandler:nil];
    }
}
#pragma mark - WLLBaseViewControllerDataSource
-(NSString *)set_title{
    return self.title;
}
//-(UIImage *)set_leftBarButtonItemWithImage{
//    return [[UIImage imageNamed:@"FLOWERLANGUAGE_ico_back"] imageChangeColor:[UIColor blackColor]];
//}
//-(void)left_button_event:(UIButton *)sender{
//    if (self.navigationController.viewControllers.count > 1){
//        [self.navigationController popViewControllerAnimated:YES];
//    } else {
//        [self dismissViewControllerAnimated:YES completion:nil];
//    }
//}
#pragma mark - 懒加载
-(WKWebView *)webView{
    if(!_webView){
        _webView = [[WKWebView alloc]init];
        _webView.navigationDelegate = self;
        _webView.UIDelegate = self;
        _webView.opaque = false;
        _webView.backgroundColor = [UIColor whiteColor];
    }
    return _webView;;
}

@end
